package com.whq.thrift.api.web.admin.db.verify;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface MerchantApiPermissionMapper {
	
	@Insert("INSERT INTO t_merchant_api_permission "
			+ " (merchant_name, api_method, ip_white_list, create_time, update_time) "
			+ " VALUES "
			+ " (#{merchantName}, #{apiMethod}, #{ipWhiteList}, #{createTime}, #{updateTime})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
    public void addMerchantApiPermission(MerchantApiPermission merchantApiPermission);
	
	@Delete("delete from t_merchant_api_permission where id=#{id}")
	public void delMerchantApiPermission(@Param("id") int id);
	
	@UpdateProvider(type = MerchantApiPermissionSqlProvider.class, method = "getUpdateSql")
	public void updMerchantApiPermission(MerchantApiPermission merchantApiPermission);
    
	@SelectProvider(type = MerchantApiPermissionSqlProvider.class, method = "getSelectMerchantApiPermissionsSql")
	@Results(
			value = {
					@Result(property="id", column="id"),
					@Result(property="merchantName", column="merchant_name"),
					@Result(property="apiMethod", column="api_method"),
					@Result(property="ipWhiteList", column="ip_white_list"),
					@Result(property="createTime", column="create_time"),
					@Result(property="updateTime", column="update_time")
			}
		)
    public List<MerchantApiPermission> getMerchantApiPermissionList(Map<String, Object> map);
	
	@SelectProvider(type = MerchantApiPermissionSqlProvider.class, method = "getSelectCountSql")
    public int getMerchantApiPermissionsCount(Map<String, Object> map);
	
	@Select("select * from t_merchant_api_permission where id=#{id}")
	@Results(value = { 
			@Result(property="id", column="id"),
			@Result(property="merchantName", column="merchant_name"),
			@Result(property="apiMethod", column="api_method"),
			@Result(property="ipWhiteList", column="ip_white_list"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time")
			}
	)
	public MerchantApiPermission getMerchantApiPermissionById(@Param("id") int id);
	
	@Select("select * from t_merchant_api_permission where merchant_name=#{merchantName}")
	@Results(value = { 
			@Result(property="id", column="id"),
			@Result(property="merchantName", column="merchant_name"),
			@Result(property="apiMethod", column="api_method"),
			@Result(property="ipWhiteList", column="ip_white_list"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time")
			}
	)
	public MerchantApiPermission getMerchantApiPermissionByName(@Param("merchantName") String merchantName);
	
	@Select("select * from t_merchant_api_permission where api_method=#{api}")
	@Results(value = { 
			@Result(property="id", column="id"),
			@Result(property="merchantName", column="merchant_name"),
			@Result(property="apiMethod", column="api_method"),
			@Result(property="ipWhiteList", column="ip_white_list"),
			@Result(property="createTime", column="create_time"),
			@Result(property="updateTime", column="update_time")
			}
	)
	public MerchantApiPermission getMerchantApiPermissionByApi(@Param("api") String api);
	
}
